
import { _decorator, Component, Node, Label } from 'cc';
import PlayerData from '../../Script/Common/PlayerData';
import Action3dManager, { ActionMngType } from '../../Script/Common/Action3dManager';
import EventManager from '../../Script/Common/EventManager';
import { EventType } from '../../Script/GameSpecial/GameEventType';
import { GlobalEnum } from '../../Script/GameSpecial/GlobalEnum';
const { ccclass, property } = _decorator;

@ccclass('LevelTip')
export class LevelTip extends Component {
    @property(Label)
    protected lvLabel: Label = null;

    protected firstEnter: boolean = true;
    onEnable() {
        if (this.firstEnter) {
            this.firstEnter = false;
            this.updateLevelNum();
            return;
        }
        this.lvLabel.node.setScale(1, 1, 1);
        let delay = Action3dManager.delay(0.5);
        let s = 10;
        let scale = Action3dManager.scaleTo(0.6, s, s, s);
        scale.easing(Action3dManager.easeIn(2));
        let fadeOut = Action3dManager.fadeTo(0.6, 1);
        fadeOut.easing(Action3dManager.easeIn(2));
        let sp1 = Action3dManager.spawn(scale, fadeOut);
        let cb = Action3dManager.callFun(this.updateLevelNum, this);
        let fadeIn = Action3dManager.fadeTo(0, 255);
        s = 1;
        let scale2 = Action3dManager.scaleTo(0.1, s, s, s);
        let seq = Action3dManager.sequence(delay, sp1, cb, fadeIn, scale2);
        Action3dManager.getMng(ActionMngType.UI).runAction(this.lvLabel.node, seq);
        // EventManager.emit(EventType.Common.AudioEvent.playEffect, GlobalEnum.AudioClip.lvChange);
    }
    updateLevelNum() {
        let level = PlayerData.getData("gameData.curLevel");
        this.lvLabel.string = level;
    }
}

